#include <cctype>
#include <iostream>
#include <fstream>
#include <string>
#include <map>
using std::cout;
using std::endl;
using std::ifstream;
using std::ofstream;
using std::string;
using std::map;

class dictionary{
public:
    bool is_word(const string & word);
    void read_dict(const string & filename);
    void write_dict(const string & filename);

private:
    map<string,int> word_count;
};
bool dictionary::is_word(const string & word){
    for(auto & ch : word){
        if(!isalpha(ch)){
            return false;
        }
    }
    return true;
}

void dictionary::read_dict(const string & filename){
    ifstream ifs(filename);
    string word;
    while(ifs >> word){
        if(is_word(word)){
            word_count[word] += 1;
        }
        word.clear();
    }
}

void dictionary::write_dict(const string & filename){
    ofstream ofs(filename);
    for(auto & ele : word_count){
        ofs << ele.first << ":" << ele.second << endl;
    }
}

void test(){
    dictionary dic;
    dic.read_dict("The_Holy_Bible.txt");
    dic.write_dict("word_count.data");
}

int main()
{
    test ();
    return 0;
}

